<?php

namespace YouBaoLian;

use YouBaoLian\Application\Request\Request;
use YouBaoLian\Application\Request\VehicleActualPriceRequest;
use YouBaoLian\Application\Request\VehicleElecPolicyRequest;
use YouBaoLian\Application\Request\VehicleModelRequest;
use YouBaoLian\Application\Request\VehicleNoCarProductDetailRequest;
use YouBaoLian\Application\Request\VehicleNoCarProductRequest;
use YouBaoLian\Application\Request\VehiclePaymentRequest;
use YouBaoLian\Application\Request\VehiclePriceDetailRequest;
use YouBaoLian\Application\Request\VehicleQueryPriceStatusRequest;
use YouBaoLian\Application\Request\VehicleQuerySalesPersonRequest;
use YouBaoLian\Application\Request\VehicleQuerySpecialRequest;
use YouBaoLian\Application\Request\VehicleQuoteRequest;
use YouBaoLian\Application\Request\VehicleRenewalRequest;
use YouBaoLian\Application\Request\VehicleRevokeRequest;
use YouBaoLian\Application\Request\VehicleSendSmsCodeRequest;
use YouBaoLian\Application\Request\VehicleSubmitUnderWriteRequest;
use YouBaoLian\Application\Request\VehicleUploadImgRequest;
use YouBaoLian\Application\Request\VehicleVerifySmsCodeRequest;
use YouBaoLian\Application\Response\VehicleActualPriceResponse;
use YouBaoLian\Application\Response\VehicleElecPolicyResponse;
use YouBaoLian\Application\Response\VehicleModelResponse;
use YouBaoLian\Application\Response\VehicleNoCarProductDetailResponse;
use YouBaoLian\Application\Response\VehicleNoCarProductResponse;
use YouBaoLian\Application\Response\VehiclePaymentResponse;
use YouBaoLian\Application\Response\VehiclePriceDetailResponse;
use YouBaoLian\Application\Response\VehicleQueryPriceStatusResponse;
use YouBaoLian\Application\Response\VehicleQuerySalesPersonResponse;
use YouBaoLian\Application\Response\VehicleQuerySpecialResponse;
use YouBaoLian\Application\Response\VehicleQuoteResponse;
use YouBaoLian\Application\Response\VehicleRenewalResponse;
use YouBaoLian\Application\Response\VehicleRevokeResponse;
use YouBaoLian\Application\Response\VehicleSendSmsCodeResponse;
use YouBaoLian\Application\Response\VehicleSubmitUnderWriteResponse;
use YouBaoLian\Application\Response\VehicleUploadImgResponse;
use YouBaoLian\Application\Response\VehicleVerifySmsCodeResponse;
use YouBaoLian\Common\Base;
use YouBaoLian\Config\Config;


/**
 * @method VehicleRenewalResponse               renewal(VehicleRenewalRequest $renewalRequest)
 * @method VehicleModelResponse                 model(VehicleModelRequest $vehicleModelRequest)
 * @method VehicleNoCarProductResponse          noCarProduct(VehicleNoCarProductRequest $vehicleNoCarProductRequest)
 * @method VehicleQuoteResponse                 quote(VehicleQuoteRequest $vehicleQuoteRequest)
 * @method VehicleUploadImgResponse             uploadImg(VehicleUploadImgRequest $vehicleUploadImgRequest)
 * @method VehicleQuerySpecialResponse          querySpecial(VehicleQuerySpecialRequest $vehicleQuerySpecialRequest)
 * @method VehicleSubmitUnderWriteResponse      underwriting(VehicleSubmitUnderWriteRequest $vehicleSubmitUnderWriteRequest) 核保提交接口
 * @method VehiclePaymentResponse               paying(VehiclePaymentRequest $vehiclePaymentRequest) 支付接口
 * @method VehicleSendSmsCodeResponse           sendSmsCode(VehicleSendSmsCodeRequest $vehicleSendSmsCodeRequest)短信发送接口
 * @method VehicleVerifySmsCodeResponse         verifySmsCode(VehicleVerifySmsCodeRequest $vehicleVerifySmsCodeRequest) 短信消费接口
 * @method VehicleElecPolicyResponse            ePolicy(VehicleElecPolicyRequest $elecPolicyRequest) 电子保单接口
 * @method VehicleRevokeResponse                revoke(VehicleRevokeRequest $vehicleRevokeRequest) 撤单接口
 * @method VehiclePriceDetailResponse           priceDetail(VehiclePriceDetailRequest $vehiclePriceDetailRequest) 报价单详情查询接口
 * @method VehicleQuerySalesPersonResponse      querySalesPerson(VehicleQuerySalesPersonRequest $vehicleQuerySalesPersonRequest)从业人员查询接口
 * @method VehicleQueryPriceStatusResponse      queryPriceStatus(VehicleQueryPriceStatusRequest $vehicleQueryPriceStatusRequest) 查询报价单状态
 * @method VehicleNoCarProductDetailResponse    noCarProductDetail(VehicleNoCarProductDetailRequest $vehicleNoCarProductDetailRequest) 非车产品责任明细查询接口
 * @method VehicleActualPriceResponse           actualPrice(VehicleActualPriceRequest $vehicleActualPriceRequest) 计算车辆实际价值接口
 */
class YouBaoLian extends Base
{

    public function __construct($array)
    {
        $this->config($array);
    }

    private function config($array)
    {
        $this->config = new Config();
        $this->config->setAppId($array['appId'] ?? '');
        $this->config->setGateway($array['gateway'] ?? '');
        $this->config->setPrivateKey($array['privateKey'] ?? '');
        $this->config->setPublicKey($array['publicKey'] ?? '');
        $this->config->setEncryptKey($array['encryptKey'] ?? '');
        $this->config->setLogsDir($array['logsDir'] ?? '');
        $this->config->setTimeout((int)($array['timeout'] ?? 60));
    }

    public function __call($name, $arguments)
    {
        $request = $arguments[0] ?? '';

        if (!$request instanceof Request) {
            throw new \Exception("request $request is not support");
        }

        return $this->execute($request);
    }
}
